<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
    <div id="app">
        <com1></com1>
    </div>
    <script>
        let com2={
            template:'<div>组件2</div>',
            inject: ['a'],
            created () {
                console.log(this.a) 
            }
        }
        let com1={
            template:`<div>
                 <h2>组件1</h2>
                 <com2></com2>   
            </div>`,
            components:{
                com2
            }
        } 
        
        new Vue({
            el:'#app',
            components:{
               com1
            },
            provide:{
                a:1
            }
        })
    </script>
</body>
</html>